PowerShell is a scripting technology that can be used
to automate many of the tasks an administrator must perform. It is
performed through a console, on the server running PowerShell.
Provisioning sites at enterprise companies is one of
those tasks that can be automated. While this can be performed through
the Central Administration interface, it is more efficient to perform
this task through PowerShell.
This recipe will show how to provision a site collection.
Getting ready
User must have access to one of the servers running PowerShell 2.0 and must be a member of the WSS_ADMIN_WPG role on the local computer. User must also be a member of the db_owner database role&; and the SharePoint_Shell_Access role in the following databases:
How to do it...
Click on the Start button on the web front-end.
Under All Programs, navigate to the Microsoft SharePoint 2010 Products folder.
Right-click SharePoint 2010 Management Shell and select the Run as Administrator option. The PowerShell console will appear.
Type in the following commands into the console window, pressing the Enter key after each command:
$url = "http://2008server/ts"
$SiteTitle = "Team Site"
$teamsite = Get-SPWebTemplate "STS#0"
New-SPSite -URL $url -OwnerAlias domain/username -Template $teamsite -name $SiteTitle
You will see the screen confirming that the site has now been created (refer to the next screenshot).&;&;
How it works...
This is a very simple PowerShell script that creates a site collection. These scripts can be combined into a .ps1
file. By doing this, the administrator can automate the creation of
sites and utilize parameters or reference an XML file to create multiple
sites.
The first line assigns the new site collection URL, http://2008server/ts, to the $url variable. Team Site is the name of the site collection.
Get-SPWebTemplate&; gets all the available SharePoint site templates. STS#0 is the template for the Team Site site collection and is assigned to the $teamsite variable&;.
New-SPSite&; utilizes all the variables and, using a domain account, creates the site collection ts. The account will be made the Site Collection Administrator for the newly created site collection.
There's more...
This is only one example of the New-SPSite command&;. However, if you type Get-help New-SPSite examples in the PowerShell console, you are provided with three additional examples.
Typing in Get-help New-SPSite full gives you a brief description of the parameters and notifies you which ones are required.&;&;